<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<title>Redirecting to Direct URL</title>
<script>
	/* 
	WIDGET FOR EXTENDING BLACKBOARD CAPABILITY, UNIVERSITY OF READING
	DEEP LINK JS
	
	MIT/X11 LICENSE
	Copyright (C) 2012 Guy Pursey (@ University of Reading)

	Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
	*/

	"use strict";
	/*jslint browser: true */

	window.onload = function () {
		var whichPage = window.location.search.substring(1).replace(/\=/g, ''), // e.g. 168&_76979&_1333596&0 (with '=' signs removed for SP10, which for some reason inserts them)
			pgInf = whichPage.split("&"), // [0] tab id [1] course id [2] content id [3] content type (all optional)
			reDirect = window.location.protocol + '//' + window.location.host, // Bb home page
			appendURL = '&url=',
			defaultSuffix = '_1';

		try {
			if (pgInf[0]) { // if tab id provided
				reDirect += '/webapps/portal/frameset.jsp?tab_tab_group_id=_' + pgInf[0] + defaultSuffix;
				if (pgInf[1]) { // if course id provided
					if (pgInf[2]) { // if content id provided
						// direct to content item
						appendURL += encodeURIComponent('/webapps/blackboard/content/listContent.jsp?course_id='
							+ pgInf[1] + defaultSuffix + '&content_id=' + pgInf[2] + defaultSuffix)
							+ encodeURIComponent('#anchor_') + pgInf[2] + defaultSuffix; // final line is hash fragment for finding content item anchor
					} else {
						// course only
						appendURL += encodeURIComponent('/webapps/blackboard/execute/courseMain?course_id=' + pgInf[1]);
					} 
				} /* replace with nested ternary operator conditions? */
				reDirect += appendURL;
			} else {
				document.getElementById('error_msg').innerHTML = 'Tried to redirect you to a page in Blackboard but failed.';
			} 

			window.location.href = reDirect;

		} catch (err) {
			document.getElementById('error_msg').innerHTML = 'Tried to redirect you to a page in Blackboard but failed.';
		}
	};

</script>
</head>
<body>
<div id="error_msg">
Loading...
</div>
</body>
</html>